package com.campus_information_portal.dao;

import com.campus_information_portal.entity.ProjectCondition;

/**
 * @author 20155884 王晓阳
 * @className : ProjectSqlProvider
 * @Description
 * @create 2018/05/31 16:29$
 **/
public class ProjectSqlProvider {
    /**
     * @param
     * @Description 条件查询社会实践
     * @author 20155884 王晓阳
     * @methodName
     * @returnType
     * @create 2018/5/31 16:30
     **/
    public String queryProject(ProjectCondition projectCondition) {
        StringBuffer sql = new StringBuffer("select project.*,student.stu_info_id,student.stu_name,student.stu_num ,term.* " +
                "FROM project,student ,term " +
                "WHERE project.stu_info_id=student.stu_info_id AND project.term_id=term.term_id " +
                "AND project_state<>0 AND project_state<>1 AND project_state<>2");
        //社会实践id---
        if (projectCondition.getProjectId() != null) {
            //  sql.append(" and course_id=#{courseId}");
            sql.append(" and project.project_id=#{projectId}");
            System.out.println("--project_id--" + projectCondition.getProjectId());
        }
        //学年
        if (projectCondition.getTermYear() != null && !("".equals(projectCondition.getTermYear()))) {
            sql.append(" and term.term_year=#{termYear}");
            System.out.println("-SqlProvider-term_year--" + projectCondition.getTermYear());
        }
        //学期
        if (projectCondition.getTermNum() != null && !("".equals(projectCondition.getTermNum()))) {
            sql.append(" and term.term_num=#{termNum}");
            System.out.println("-SqlProvider-term_num--");
        }
        //状态
        if (projectCondition.getProjectState() != null && !("".equals(projectCondition.getProjectState()))) {
            sql.append(" and project.project_state=#{projectState}");
            System.out.println("-MarkSqlProvider-termYear--");
        }
        //学生学号
        if (projectCondition.getStuNum() != null && !("".equals(projectCondition.getStuNum()))) {
            sql.append(" and student.stu_num=#{stuNum}");
            System.out.println("-SqlProvider-stu_num--");
        }
        //学生id
        if (projectCondition.getStuInfoId() != null && !("".equals(projectCondition.getStuInfoId()))) {
            sql.append(" and student.stu_info_id=#{stuInfoId}");
            System.out.println("-SqlProvider-stu_info_id--");
        }
        //学生姓名
        if (projectCondition.getStuName() != null && !("".equals(projectCondition.getStuName()))) {
            sql.append(" and student.stu_name=#{stuName}");
            System.out.println("-SqlProvider-stu_name--");
        }
        return sql.toString();
    }
}
